package com.y.ari.controller;

import com.y.ari.common.RestResponse;
import com.y.ari.dto.FlightDTO;
import com.y.ari.dto.FlightFormDTO;
import com.y.ari.dto.PageDTO;
import com.y.ari.entity.PageParams;
import com.y.ari.service.FlightService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 航班信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("/flight")
public class FlightController {

    @Autowired
    private FlightService flightService;

    @PostMapping("/sel")
    public RestResponse selFlight(@RequestBody FlightFormDTO flightFormDTO) {

        if (flightFormDTO.getCityFrom() == null ||
                flightFormDTO.getCityTo() == null ||
                flightFormDTO.getDepartureData() == null) {
            return RestResponse.validfail("参数错误");

        }
        List<FlightDTO> flightList = flightService.selFlight(flightFormDTO);
        if (flightList == null) {
            return RestResponse.validfail("当前没有航班");
        }
        return RestResponse.success(flightList, "");

    }

    @PostMapping("/selPage")
    public RestResponse selFlight(@RequestBody PageParams pageParams) {
        PageDTO pageDTO = flightService.selPage(pageParams);
        return RestResponse.success(pageDTO, "");
    }

    @PostMapping("/save")
    public RestResponse saveFC(@RequestBody FlightDTO flightDTO) {
        return flightService.saveFC(flightDTO);

    }

    @DeleteMapping("/del/{id}")
    public RestResponse del(@PathVariable Long id) {
        return flightService.delFC(id);

    }


}
